package com.woniuxy.oldobject.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.oldobject.dao.ElderInfoDao;
import com.woniuxy.oldobject.dao.StaffDao;
import com.woniuxy.oldobject.dto.StaffDto;
import com.woniuxy.oldobject.entity.ElderInfo;
import com.woniuxy.oldobject.entity.Staff;
import com.woniuxy.oldobject.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author： 倪和楠
 * @Todo：
 * @Date： 2022/7/22 9:31
 * @Version： 1.0
 */
@Service
public class StaffServiceImpl extends ServiceImpl<StaffDao, Staff> implements StaffService {

    @Autowired
    StaffDao staffDao;
    @Autowired
    ElderInfoDao elderInfoDao;

    @Override
    public Staff queryById(Integer id) {
        return staffDao.queryById(id);
    }

    @Override
    public List<Staff> queryAllByLimit(Staff staff, Pageable pageable) {
        return staffDao.queryAllByLimit(staff, pageable);
    }

    @Override
    public List<Staff> queryAllByLimitPgaeInfo(StaffDto staff) {
        if ( staff.getOlderName().length() != 0  ) {
            ElderInfo elderInfo = elderInfoDao.queryByName(staff.getOlderName());
            staff.setElderId(elderInfo.getStaff().getId());
        }
        return staffDao.queryAllByLimitPgaeInfo(staff);
    }

    @Override
    public long count(Staff staff) {
        return staffDao.count(staff);
    }

    @Override
    public int insert(Staff staff) {
        return staffDao.insert(staff);
    }

    @Override
    public int insertBatch(List<Staff> entities) {
        return staffDao.insertBatch(entities);
    }

    @Override
    public int insertOrUpdateBatch(List<Staff> entities) {
        return staffDao.insertOrUpdateBatch(entities);
    }

    @Override
    public int update(Staff staff) {
        return staffDao.update(staff);
    }

    @Override
    public int deleteById(Integer id) {
        return staffDao.deleteById(id);
    }

    @Override
    public Staff queryStaffWithOlders(int id) {
        return staffDao.queryStaffWithOlders(id);
    }

    @Override
    public List<Staff> queryStaffWithOldersNoId() {
        return staffDao.queryStaffWithOldersNoId();
    }

    @Override
    public boolean updates(StaffDto staffDto) {
        return staffDao.updates(staffDto);
    }

    @Override
    public boolean updateByOlder(StaffDto staffDto) {
        ElderInfo elderInfo = elderInfoDao.selectByStaffId(staffDto.getStaffId());
        if (elderInfo == null) {
            return staffDao.updateByOlder(staffDto);
        }
        return false;
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @param staff 实例对象
     * @return 对象列表
     */
    @Override
    public List<Staff> queryAll(Staff staff) {
        return staffDao.queryAll(staff);
    }

    /**
     * 查询所有员工不带条件
     *
     * @return
     */
    @Override
    public List<Staff> SelectAll() {
        return staffDao.SelectAll();
    }

}
